package com.come4loves.game.module.actor.dao.impl;

import org.springframework.stereotype.Component;

import com.come4loves.core.dbcenter.dao.BaseDaoImpl;
import com.come4loves.game.dbproxy.IdTableJdbc;
import com.come4loves.game.dbproxy.entity.Actor;
import com.come4loves.game.module.actor.dao.ActorDao;

@Component
public class ActorDaoImpl extends BaseDaoImpl implements ActorDao {


	@Override
	public Actor getActor(long actorId) {
		return get(actorId, Actor.class);
	}
	
	@Override
	public long createActor(int serverId) {
		long actorId = 0;
		Actor actor = new Actor();
		try {
			IdTableJdbc idJdbc = (IdTableJdbc) this.jdbc;
			actorId = idJdbc.saveLongPK(actor);
			if (actorId <= 0) {
				throw new RuntimeException("actorId error");
			}
			this.dataCache.setToCache(actorId, actor);
		} catch (Exception e) {
			LOGGER.error("{}", e);
		}
		return actorId;
	}
	
	@Override
	public boolean exsit(long actorId) {
		Actor actor = getExsit(actorId, Actor.class);
		return actor != null;
	}
	
}
